/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CompanyExtManager;
/*     */ import com.newcrm.db.UserVOIPManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.sql.SQLException;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class UpdateVOIPSetting extends AbstractAction
/*     */ {
/*  36 */   private static Logger logger = Logger.getLogger(UpdateVOIPSetting.class
/*  37 */     .getName());
/*     */ 
/*  39 */   private String id = null;
/*     */ 
/*     */   public UpdateVOIPSetting(AbstractHttpServlet servlet, String id) {
/*  42 */     super(servlet);
/*  43 */     this.id = id;
/*     */   }
/*     */ 
/*     */   public UpdateVOIPSetting(AbstractHttpServlet servlet) {
/*  47 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  53 */     response.setContentType("text/html;charset=utf-8");
/*  54 */     PrintWriter out = response.getWriter();
/*  55 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  57 */     User user = super.getLoginUser(request);
/*     */ 
/*  59 */     if ((!user.userId.equals(this.id)) && (!user.isAdmin)) {
/*  60 */       super.showErrorMessage(response, "您没有操作的权限");
/*  61 */       return;
/*     */     }
/*     */ 
/*  64 */     String username = 
/*  65 */       Util.getURLParameter(request.getParameter("username"));
/*  66 */     String password = Util.getURLParameter(request.getParameter("pwd"));
/*     */ 
/*  68 */     UserVOIPManager manager = new UserVOIPManager();
/*     */     try
/*     */     {
/*  71 */       if (((username == null) || (username.trim().length() == 0)) && (
/*  72 */         (password == null) || (password.trim().length() == 0))) {
/*  73 */         manager.clear(user.companyId, this.id);
/*     */       } else {
/*  75 */         int result = manager.update(this.id, username, password, null);
/*  76 */         if (result == 0) {
/*  77 */           manager.add(this.id, username, password, null, 
/*  78 */             user.companyId);
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*  83 */       if (this.id.equals(user.userId)) {
/*  84 */         HttpSession session = request.getSession();
/*  85 */         if (session != null)
/*  86 */           if (((username == null) || (username.trim().length() == 0)) && (
/*  87 */             (password == null) || (password.trim().length() == 0))) {
/*  88 */             session.removeAttribute("voip");
/*     */           }
/*     */           else {
/*  91 */             Map voip = new HashMap();
/*  92 */             voip.put("UserName", username);
/*  93 */             voip.put("UserPwd", password);
/*     */ 
/*  95 */             CompanyExtManager companyExtManager = new CompanyExtManager();
/*  96 */             String serverIP = companyExtManager.getFieldValue(
/*  97 */               user.companyId, 
/*  98 */               6);
/*  99 */             if (serverIP == null) {
/* 100 */               serverIP = "";
/*     */             }
/* 102 */             voip.put("ServerIP", serverIP);
/*     */ 
/* 104 */             String appId = companyExtManager.getFieldValue(
/* 105 */               user.companyId, 
/* 106 */               4);
/* 107 */             if (appId == null) {
/* 108 */               appId = "";
/*     */             }
/* 110 */             voip.put("AppID", appId);
/* 111 */             session.setAttribute("voip", voip);
/*     */           }
/*     */       }
/*     */     }
/*     */     catch (SQLException|DBException e)
/*     */     {
/* 117 */       logger.warn("update user voip setting failed", e);
/*     */     }
/*     */ 
/* 120 */     jsonObject.put("error", "0");
/* 121 */     out.println(jsonObject);
/* 122 */     out.flush();
/* 123 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.UpdateVOIPSetting
 * JD-Core Version:    0.6.1
 */